<template>
	<view class="page-container" :style="{'background-image':`url(${pageBg})`}" @touchmove.stop.prevent>
    <view class="label-list">
      <view class="label flex-cc" v-for="(label, index) in labelList" :key="index">{{label}}</view>
    </view>
    <view class="buy-intro-page">
			<view class="img-1">
				<view class="img" :style="{backgroundImage: `url(${staticImgs.toUnlockImg_1})`}">
          <view class="scl-row flex-cc" v-for="(info,index) in baseSclList" :key="index" :style="{left: info.style.left, top: info.style.top}">
            <view class="col-3">&yen;&nbsp;{{info.price}}</view>
          </view>
          <view class="info-wrapper">
            <view class="info">
              <view class="info-row">
                <view class="col-1">优惠减免</view>
                <view class="col-2">-&yen;&nbsp;{{priceObj.deratePrice || '0'}}</view>
              </view>
              <view class="info-row">
                <view class="col-1 t-1">限时特价</view>
                <view class="col-2 price-type-3">&yen;&nbsp;{{priceObj.payPrice || ''}}</view>
              </view>
            </view>
          </view>
        </view>
			</view>
			<view class="img-2">
				<image class="img" :src="staticImgs.toUnlockImg_2" mode="widthFix"></image>
			</view>
		</view>
		<view class="btn-img" @click="toOrderPay">
			<image class="img" :src="staticImgs.toUnlockBtn" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	import {
		debounce
	} from 'lodash'

	export default {
		data() {
			return {
				pageBg: "",
				staticImgs: {
					toUnlockBtn: this.imgBaseURL + "/scl/checkup-sexuality/main/to-unlock-btn-img.png",
					toUnlockImg_1: this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_main.png",
					toUnlockImg_2: this.imgBaseURL + "/scl/checkup-sexuality/main/to-unlock-img-2.png"
				},
				page: 'page-1',
				priceObj: {},
				giftInfo: {},
				baseSclList: [],
				pageLoading: false,
				payGroupId: '',
				opts: {},
				sclId: '',
				// 分享配置
				shareData: {
					title: '性取向综合鉴定指南',
					path: '/pages/index/index?userType=sexuality-assessment',
					imageUrl: this.imgBaseURL + "/scl/checkup-sexuality/share.png",
					desc: '',
					content: ''
				},
        labelList: []
			}
		},
		onLoad(opts) {
			this.sclId = opts.sclId
			this.reportId = opts.reportId
			this.opts = opts
      this.payGroupId = this.sclId
			console.log(this.opts, '===this.opts==')

			this.$u.api.getSclListByGroup({
				sclTotalCode: this.$dictMap.CHECKUP_SEXUALITY
			}).then(({
				data: res
			}) => {
				console.log(res, '----------this.$dictMap.CHECKUP_SEXUALITY')
				const {
					deratePrice,
					sumPrice,
					price,
					sclExaminationBOS,
					sclId
				} = res.data
				this.payGroupId = sclId||this.sclId

				this.priceObj.sumPrice = sumPrice
				this.priceObj.deratePrice = deratePrice
				this.priceObj.payPrice = price

				const gitfScl = sclExaminationBOS.find(item => item.remark == '我的恋爱MBTI')

				const tmpArr = []
				sclExaminationBOS.map(item => {
					if (item.remark != gitfScl.remark) {
            const obj = {
              name: item.sclName,
              price: item.newOriginalPrice,
              style: {}
            }
            if (obj.name.includes('安全感')) {
              obj.style = {
                left: '103rpx',
                top: '118rpx'
              }
            } else if (obj.name.includes('桃花缘')) {
              obj.style = {
                left: '506rpx',
                top: '118rpx'
              }
            } else if (obj.name.includes('性取向')) {
              obj.style = {
                left: '95rpx',
                top: '222rpx'
              }
            } else if (obj.name.includes('恋爱态度')) {
              obj.style = {
                left: '508rpx',
                top: '218rpx'
              }
            }
            tmpArr.push(obj)
					}
				})
				this.baseSclList = tmpArr


				this.giftInfo.name = gitfScl.sclName
				this.giftInfo.price = gitfScl.newOriginalPrice

			})
		},
		onShow() {
			this.setPageBg()
		},
		methods: {
			backHandle() {
				uni.reLaunch({
					url: '/pages/sclList/sclList'
				})
			},
			setPageBg() {
				this.$u.api.sclSexualOrientationLabel().then(({
					data: res
				}) => {

					if (res.data && res.data[0]) {
						const tmpRes = res.data[0]
						console.log(tmpRes, '===tmpRes')
						if (tmpRes == '美丽的小姐姐') {
							this.pageBg = this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_bg_v2.png"
						} else if (tmpRes == '帅气的小哥哥') {
							this.pageBg = this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_bg_nan_v2.png"
						} else if (tmpRes == '特立独行的跨性别者') {
							this.pageBg = this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_bg_kua_v2.png"
						} else if (tmpRes == '充满魅力的无性别者') {
							this.pageBg = this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_bg_wu_v2.png"
						} else if (tmpRes == '雨露均沾的双性别者') {
							this.pageBg = this.imgBaseURL + "/scl/checkup-sexuality/main/new_paypage_bg_shuang_v2.png"
						}
            this.labelList = res.data.slice(1)
					}
				})
			},
			changePage(p) {
				this.page = p
			},
			toOrderPay: debounce(function() {
				if (this.pageLoading) return
				const submitForm = this.$removeEmptyProperty({
					orderType: '12',
					sclId: this.payGroupId
				})
				const that = this
				this.pageLoading = true
				uni.showLoading()
				this.$u.api.addLog({
					sclId: this.payGroupId,
					sourseType: 1
				})
				this.$u.api.orderPay(submitForm).then(res => {
					if (res.data.code == 200) {
						uni.requestPayment({
							provider: 'wxpay',
							service: 5,
							orderInfo: res.data.data.wr,
							timeStamp: res.data.data.wr.timeStamp,
							nonceStr: res.data.data.wr.nonceStr,
							package: res.data.data.wr.packageValue,
							signType: res.data.data.wr.signType,
							paySign: res.data.data.wr.paySign,
							success: function(res) {
								console.log(res, '================= uni.requestPayment - res')
                uni.redirectTo({
                  url: '/subcontractorB/pages/sclResult/sclResult?id=' +
                      that.reportId +
                      '&sclReportType=3'
                })
                that.pageLoading = false
                uni.hideLoading()
							},
							fail() {
								that.pageLoading = false
								uni.hideLoading()
							}
						})
					} else {
						that.$showToast(res.data.message);
						that.pageLoading = false
						uni.hideLoading()
					}
				}).catch(e => {
					that.pageLoading = false
					uni.hideLoading()
				})
			}, 500)
		}
	}
</script>

<style lang="scss" scoped>
	@keyframes btn-animation {
		0% {
			opacity: 0;
		}

		100% {
			opacity: 1;
		}
	}

	.page-container {
		position: relative;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		height: 100vh;
		background-size: cover;
		transition: all .8s ease-in-out;
		background-color: #1c3a5d;
		opacity: 0;
		animation: 1s btn-animation ease-in-out 1;
		animation-fill-mode: forwards;

		.btn-img {
			width: 500rpx;
			height: 140rpx;
      margin-bottom: 35rpx;

			.img {
				width: 100%;
				height: 100%;
			}
		}

		.buy-intro-page {
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;
			width: 100%;

			.img {
				width: 100%;
				height: 100%;
			}

			.img-1 {
				width: 710rpx;
				height: 482rpx;

        .img {
          background-position: center center;
          background-repeat: no-repeat;
          background-size: 100% 100%;
          position: relative;
        }
			}

			.img-2 {
				width: 660rpx;
				height: 160rpx;
				margin-top: 6rpx;
				margin-bottom: 18rpx;
			}



		}

    .scl-row {
      position: absolute;
      background-image: linear-gradient(180deg, #81C4FF 0%, #182238 100%);
      border-radius: 10rpx 10rpx 0 0;
      min-width: 104rpx;
      height: 38rpx;

      .col-3 {
        font-weight: bold;
        font-size: 28rpx;
        color: #FFEF3E;
        line-height: 40rpx;
      }
    }

    .info-wrapper {
      padding-top: 330rpx;
    }

    .info {
      width: 511rpx;
      border-top: 3rpx dashed #39B5D9;
      padding-top: 9rpx;
      margin: 0 auto;
    }

    .info-row {
      display: flex;
      justify-content: space-between;
      font-size: 28rpx;
      color: #FFF;
      line-height: 40rpx;
      align-items: center;

      .t-1 {
        font-weight: bold;
        font-size: 28rpx;
        color: #FFEF3E;
        line-height: 40rpx;
      }

      .price-type-3 {
        font-weight: bold;
        font-size: 40rpx;
        color: #FFEF3E;
        line-height: 56rpx;
      }

    }
  }

  .label-list {
    position: relative;
    width: 100%;
    flex: 1 0 auto;

    .label {
      height: 60rpx;
      background-image: linear-gradient( 90deg, #FFFFFF 0%, rgba(255,255,255,0.62) 50%, #FFFFFF 100%);
      box-shadow: 0 2rpx 10rpx 0 #3575B6;
      border-radius: 30rpx;
      font-weight: bold;
      font-size: 30rpx;
      color: #062442;
      position: absolute;
      padding: 0 20rpx;

      &:first-child {
        top: 685rpx;
        left: 36rpx;
      }

      &:nth-child(2) {
        top: 528rpx;
        left: 36rpx;
      }

      &:nth-child(3) {
        top: 588rpx;
        left: 426rpx;
      }
    }
  }
</style>